package com.work.biz.service.impl;

import java.util.Date;
import java.util.List;

import com.work.biz.domain.BizCounselor;
import com.work.biz.mapper.BizCounselorMapper;
import com.work.biz.service.IBizCounselorService;
import com.work.common.utils.DateUtils;
import com.work.sys.mapper.SysUserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.work.biz.mapper.BizSchoolMapper;
import com.work.biz.domain.BizSchool;
import com.work.biz.service.IBizSchoolService;
import org.springframework.transaction.annotation.Transactional;

/**
 * 学校Service业务层处理
 * 
 * @author  lee
 * @date 2021-04-22
 */
@Service
public class BizSchoolServiceImpl implements IBizSchoolService 
{
    @Autowired
    private BizSchoolMapper bizSchoolMapper;
    @Autowired
    private SysUserMapper userInfoMapper;
    @Autowired
    private IBizCounselorService bizCounselorService;

    /**
     * 查询学校
     * 
     * @param schoolId 学校ID
     * @return 学校
     */
    @Override
    public BizSchool selectBizSchoolById(Long schoolId)
    {
        return bizSchoolMapper.selectBizSchoolById(schoolId);
    }

    /**
     * 查询学校列表
     * 
     * @param bizSchool 学校
     * @return 学校
     */
    @Override
    public List<BizSchool> selectBizSchoolList(BizSchool bizSchool)
    {
        return bizSchoolMapper.selectBizSchoolList(bizSchool);
    }

    /**
     * 新增学校
     * 
     * @param bizSchool 学校
     * @return 结果
     */
    @Override
    @Transactional
    public int insertBizSchool(BizSchool bizSchool)
    {
        Date now = DateUtils.getNowDate();
        bizSchool.setCreateTime(now);
        String createBy = userInfoMapper.selectSysUserById(bizSchool.getUserId()).getNickName();
        bizSchool.setCreateBy(createBy);
        int m = bizSchoolMapper.insertBizSchool(bizSchool);
        BizCounselor counselor = new BizCounselor();
        counselor.setUserId(bizSchool.getUserId());
        counselor.setCounselorName(createBy);
        counselor.setSchoolId(bizSchool.getSchoolId());
        counselor.setCreateBy(createBy);
        counselor.setCreateTime(now);
        bizCounselorService.insertBizCounselor(counselor);
        return m;
    }

    /**
     * 修改学校
     * 
     * @param bizSchool 学校
     * @return 结果
     */
    @Override
    public int updateBizSchool(BizSchool bizSchool)
    {
        bizSchool.setUpdateTime(DateUtils.getNowDate());
        return bizSchoolMapper.updateBizSchool(bizSchool);
    }

    /**
     * 批量删除学校
     * 
     * @param schoolIds 需要删除的学校ID
     * @return 结果
     */
    @Override
    public int deleteBizSchoolByIds(Long[] schoolIds)
    {
        return bizSchoolMapper.deleteBizSchoolByIds(schoolIds);
    }

    /**
     * 删除学校信息
     * 
     * @param schoolId 学校ID
     * @return 结果
     */
    @Override
    public int deleteBizSchoolById(Long schoolId)
    {
        return bizSchoolMapper.deleteBizSchoolById(schoolId);
    }
}
